package refactortips.editors.designPatterns;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;

import refactortips.editors.AbstractRefactorTipsEditor;

public class AdapterEditor extends AbstractRefactorTipsEditor {

	protected final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	
	public AdapterEditor() {
	}

	/**
	 * Create contents of the editor part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		
		Form frmDesignPattern = formToolkit.createForm(parent);
		formToolkit.paintBordersFor(frmDesignPattern);
		frmDesignPattern.setText("Adapter");
		frmDesignPattern.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));
		
		TabFolder tabFolder = new TabFolder(frmDesignPattern.getBody(), SWT.NONE);
		formToolkit.adapt(tabFolder);
		formToolkit.paintBordersFor(tabFolder);
		
		ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		sc.setExpandHorizontal(true);
	    sc.setExpandVertical(true);
		
		TabItem tbtmDescription = new TabItem(tabFolder, SWT.NONE);
		tbtmDescription.setText("Descri\u00E7\u00E3o");
		
		ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmDescription.setControl(scrolledComposite);
		formToolkit.paintBordersFor(scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		Composite composite_3 = new Composite(scrolledComposite, SWT.NONE);
		formToolkit.adapt(composite_3);
		formToolkit.paintBordersFor(composite_3);
		composite_3.setLayout(null);
		
		Label lblPurpose = new Label(composite_3, SWT.NONE);
		lblPurpose.setBounds(10, 267, 102, 25);
		lblPurpose.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblPurpose.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		formToolkit.adapt(lblPurpose, true, true);
		lblPurpose.setText("Prop\u00F3sito");
		
		StyledText styledText = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText.setEnabled(false);
		styledText.setDoubleClickEnabled(false);
		styledText.setJustify(true);
		styledText.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText.setText("Permitir que classes com interfaces distintas trabalhem juntas atrav\u00E9s da cria\u00E7\u00E3o de um objeto em comum pela qual elas podem se comunicar e interagir.");
		styledText.setBounds(25, 314, 830, 60);
		formToolkit.adapt(styledText);
		formToolkit.paintBordersFor(styledText);
		
		Label lblUsarQuando = new Label(composite_3, SWT.NONE);
		lblUsarQuando.setText("Usar quando:");
		lblUsarQuando.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblUsarQuando.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		lblUsarQuando.setBounds(10, 389, 120, 25);
		formToolkit.adapt(lblUsarQuando, true, true);
		
		StyledText styledText_1 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_1.setText("- Uma classe n\u00E3o se adequa aos requisitos da interface.\r\n- Condi\u00E7\u00F5es complexas amarram o comportamento do objeto ao seu estado.\r\n- Transi\u00E7\u00F5es entre estados precisam ser expl\u00EDcitas.");
		styledText_1.setJustify(true);
		styledText_1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_1.setEnabled(false);
		styledText_1.setDoubleClickEnabled(false);
		styledText_1.setBounds(25, 436, 611, 108);
		formToolkit.adapt(styledText_1);
		formToolkit.paintBordersFor(styledText_1);
		
		Label label_2 = new Label(composite_3, SWT.NONE);
		label_2.setImage(ResourceManager.getPluginImage("RefactorTips", "images/designPatterns/adapter.png"));
		label_2.setBounds(178, 35, 458, 216);
		formToolkit.adapt(label_2, true, true);
		scrolledComposite.setContent(composite_3);
		scrolledComposite.setMinSize(composite_3.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmUsage = new TabItem(tabFolder, SWT.NONE);
		tbtmUsage.setText("Exemplo");
		
		ScrolledComposite scrolledComposite_1 = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmUsage.setControl(scrolledComposite_1);
		formToolkit.paintBordersFor(scrolledComposite_1);
		scrolledComposite_1.setExpandHorizontal(true);
		scrolledComposite_1.setExpandVertical(true);
		
		Composite composite = new Composite(scrolledComposite_1, SWT.NONE);
		formToolkit.adapt(composite);
		formToolkit.paintBordersFor(composite);
		
		Label label = new Label(composite, SWT.NONE);
		label.setText("Exemplo");
		label.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		label.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		label.setBounds(10, 10, 77, 25);
		formToolkit.adapt(label, true, true);
		
		StyledText styledText_2 = new StyledText(composite, SWT.READ_ONLY | SWT.WRAP);
		styledText_2.setText("\t\tUma aplica\u00E7\u00E3o de faturamento precisa interfacear com uma aplica\u00E7\u00E3o de RH para que possa trocar dados do empregado, entretanto cada um tem sua pr\u00F3pria interface e implementa\u00E7\u00E3o para o objeto Empregado. Al\u00E9m disso, o CPF \u00E9 armazenado em diferentes formatos por cada sistema. Ao criar um adapter n\u00F3s podemos criar uma interface comum entre as duas aplica\u00E7\u00F5es que permite que eles se comuniquem usando seus objetos nativos e \u00E9 capaz de transformar o formato do CPF no processo.");
		styledText_2.setJustify(true);
		styledText_2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_2.setEnabled(false);
		styledText_2.setDoubleClickEnabled(false);
		styledText_2.setBounds(25, 57, 831, 108);
		formToolkit.adapt(styledText_2);
		formToolkit.paintBordersFor(styledText_2);
		
		Label label_1 = new Label(composite, SWT.NONE);
		label_1.setImage(ResourceManager.getPluginImage("RefactorTips", "images/designPatterns/adapter/adapterSample1.png"));
		label_1.setBounds(174, 227, 498, 310);
		formToolkit.adapt(label_1, true, true);
		
		Label label_3 = new Label(composite, SWT.NONE);
		label_3.setText("Exemplo 2");
		label_3.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		label_3.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		label_3.setBounds(10, 192, 93, 25);
		formToolkit.adapt(label_3, true, true);
		scrolledComposite_1.setContent(composite);
		scrolledComposite_1.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmVideo = new TabItem(tabFolder, SWT.NONE);
		tbtmVideo.setText("Video");
		
		Browser browser = new Browser(tabFolder, SWT.NONE);
		browser.setUrl("www.youtube.com/embed/ND1HfLlp6pA");
		tbtmVideo.setControl(browser);
		formToolkit.paintBordersFor(browser);
	}
}
